#include "Observable.h"

Observable::Observable(void)
{
	isChanged = false;
}

Observable::~Observable(void)
{
}

void Observable::addObserver(Observer* observer)
{
	pair<map<string, Observer*>::iterator, bool> result;
	result = observers.insert(pair<string, Observer*>(observer->getId(), observer));
	if (result.second == false)
	{
	}
}

void Observable::deleteObserver(Observer* observer)
{
	map<string, Observer*>::const_iterator it;
	it = observers.find(observer->getId());
	if (it != observers.end())
	{
		observers.erase(it);
	}
}

void Observable::notifyObservers(void)
{
	map<string, Observer*>::const_iterator it;
	for (it=observers.begin(); it!=observers.end(); it++)
	{
		(*it).second->update(this);
	}
	isChanged = true;
}

bool Observable::hasChanged(void)
{
	return isChanged;
}

void Observable::clearChange(void)
{
	isChanged = false;
}
